package com.music.controller;

import com.music.dto.Result;
import com.music.entity.SongListRelation;
import com.music.service.SongListRelationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/songListRelation")
@Slf4j
public class SongListRelationController {

    @Autowired
    private SongListRelationService songListRelationService;

    @GetMapping
    public @ResponseBody
    Result getSongList(String songListId,HttpServletResponse response) throws IOException {
        //设置统一结果返回
        Result result = new Result();

        SongListRelation songListRelation = null;
        List<SongListRelation> songListRelations = new ArrayList<SongListRelation>();

        if (songListId != null){
            songListRelation = new SongListRelation();
        }
        if(songListId != null && !"".equals(songListId)){
            songListRelation.setSongListId(songListId);
        }
        songListRelations = songListRelationService.findBySongListId(songListId);
        if(!songListRelations.isEmpty()){
            result.ok(songListRelations);
        }else{
            result.fail(0,"没有相关数据");
        }
        return result;
    }
}
